const mongoose = require('mongoose');
const Mock = require('mockjs')

const { students } = Mock.mock({
    "students|100": [
        {
            name: "@cname",
            "age|20-30": 20,
            gender: "@string(男女,1)",
            phone: /^1[0-9]{10}$/,
            address: "@city(true)",
            zip: "@zip()",
        }
    ]
});

mongoose.connect('mongodb://localhost:27017/F74', {
    useNewUrlParser: true,
    useUnifiedTopology: true
}, async () => {
    const studentsSchema = new mongoose.Schema({
        name: String,
        "age|20-30": Number,
        gender: String,
        phone: String,
        address: String,
        zip: String,
    });
    const studentsModel = mongoose.model(
        'students',
        studentsSchema,
        "students"
    );
    const data = await studentsModel.create(students);
    console.log(data);
})








// console.log(students);

// mongoose.connect('mongodb://localhost:27017/F74',
//     {
//         useNewUrlParser: true,
//         useUnifiedTopology: true
//     }, () => {
//         const usersSchema = new mongoose.Schema({
//             username: String,
//             pwd: String,
//         });

//         const usersModel = mongoose.model('users', usersSchema, "users");

//         usersModel.create({
//             username: "z3",
//             pwd: "123456"
//         }, (err, data) => {
//             console.log(data);
//         })
//     });

